home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C26 / mlm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  2.2 KB  |  75 lines

  1. //: C26:mlm.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // A GGI program to maintain a mailing list
  7. #include "CGImap.h"
  8. #include <fstream>
  9. using namespace std;
  10. const string contact("Bruce@EckelObjects.com");
  11. // Paths in this program are for Linux/Unix. You
  12. // must use backslashes (two for each single 
  13. // slash) on Win32 servers:
  14. const string rootpath("/home/eckel/");
  15.  
  16. int main() {
  17.   cout << "Content-type: text/html\n"<< endl;
  18.   CGImap query(getenv("QUERY_STRING"));
  19.   if(query["test-field"] == "on") {
  20.     cout << "map size: " << query.size() << "<br>";
  21.     query.dump(cout, "<br>");
  22.   }
  23.   if(query["subject-field"].size() == 0) {
  24.     cout << "<h2>Incorrect form. Contact " <<
  25.     contact << endl;
  26.     return 0;
  27.   }
  28.   string email = query["email-address"];
  29.   if(email.size() == 0) {
  30.     cout << "<h2>Please enter your email address"
  31.       << endl;
  32.     return 0;
  33.   }
  34.   if(email.find_first_of(" \t") != string::npos){
  35.     cout << "<h2>You cannot use white space "
  36.       "in your email address" << endl;
  37.     return 0;
  38.   }
  39.   if(email.find('@') == string::npos) {
  40.     cout << "<h2>You must use a proper email"
  41.       " address including an '@' sign" << endl;
  42.     return 0;
  43.   }
  44.   if(email.find('.') == string::npos) {
  45.     cout << "<h2>You must use a proper email"
  46.       " address including a '.'" << endl;
  47.     return 0;
  48.   }
  49.   string fname = email;
  50.   if(query["command-field"] == "add")
  51.     fname += ".add";
  52.   else if(query["command-field"] == "remove")
  53.     fname += ".remove";
  54.   else {  
  55.     cout << "error: command-field not found. Contact "
  56.       << contact << endl;
  57.     return 0;
  58.   }
  59.   string path(rootpath + query["subject-field"] 
  60.     + "/" + fname);
  61.   ofstream out(path.c_str());
  62.   if(!out) {
  63.     cout << "cannot open " << path << "; Contact"
  64.       << contact << endl;
  65.     return 0;
  66.   }
  67.   out << email << endl;
  68.   cout << "<br><H2>" << email << " has been ";
  69.   if(query["command-field"] == "add")
  70.     cout << "added";
  71.   else if(query["command-field"] == "remove")
  72.     cout << "removed";
  73.   cout << "<br>Thank you</H2>" << endl;
  74. } ///:~
  75.